<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: gold;
        }
    </style>
    <script>
        window.onload = function () {

            var oDiv1 = document.getElementById("div1");

            // 如果是class属性 必须写成className
            oDiv1.className = "box";

            alert(oDiv1.className);

        }
    </script>
</head>

<body>

    <div id="div1">哈哈哈</div>


</body>

</html>